Back

Contents

Set up an nginx-ingress controller on a kubernetes cluster

Install

  1. Apply the manifest.

     $ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/baremetal/deploy.yaml
  2. (optional) Make the controller load balanced. Edit the manifest & change spec.type: LoadBalancer.

     $ kubectl edit svc ingress-nginx-controller -n ingress-nginx

    this can be checked by verifying the service is load balanced at the correct IP with:

     $ kubectl get all -n ingress-nginx

Adding a HTTP(S) ingress rule

  1. Create an ingress rule, ingress.yaml.

    The following rule will redirect a call to the controller's load balancing IP:80 to service_name:service_port.

     apiVersion: networking.k8s.io/v1beta1
     kind: Ingress
     metadata:
       name: <name>
       annotations:
         nginx.ingress.kubernetes.io/rewrite-target: /
     spec:
       rules:
       - http:
           paths:
           - path: /
             pathType: Prefix
             backend:
               serviceName: <service_name>
               servicePort: <service_port>

    where service_name can be retrieved from the output of kubectl get svc -n <namespace>.

    To accept other inbound ports at the load balancer, it is necessary to add to spec.ports listed in controller's manifest.

  2. Apply the ingress rule.

     $ kubectl apply -f ingress.yaml -n <namespace>

Adding a custom TCP service ingress rule

Assuming that ingress-nginx has been deployed and the tcp service to be ingressed is running with service_name on port service_port:

  1. Create a new configMap in namespace, namespace.

     $ vi new-configmap.yml
     apiVersion: v1
     kind: ConfigMap
     metadata:
       name: tcp-services
       namespace: <namespace>
     data:
       <service_port>: "<namespace>/<service_name>:<service_port>"
  2. Edit the ingress controller service.

     $ kubectl edit svc ingress-nginx-controller -n ingress-nginx

    and add a new entry under spec:ports::

     - name: <name>
       port: <service_port>
       protocol: TCP
       targetPort: <service_port>

    where name is arbitrary.

  3. Edit the deployment to allow tcp services.

     $ kubectl edit deployment ingress-nginx-controller -n ingress-nginx

    adding the --tcp-services flag under spec:template:spec:containers:args pointing to the configMap (with namespace):

     - args:
       - /nginx-ingress-controller
       .
       .
       - --tcp-services-configmap=<namespace>/tcp-services

Top